package com.gxa.autoparts.portal.controller;

import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.pojo.GoodsType;
import com.gxa.autoparts.portal.service.GoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：looker
 * @date ：Created in 2022/1/8 16:09
 * 商品分类控制器
 */
@RestController
@RequestMapping("/goodsType")
@Api(tags = "商品分类控制器")
public class GoodsTypeController {
    @Autowired
    GoodsTypeService goodsTypeService;

    @PostMapping("/getTopTypes")
    @ApiOperation("获取一级分类")
    public Map getTopTypes(){
        List<GoodsType> topLevel = goodsTypeService.getTopLevel();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(topLevel);
        return jsonResult.getDataMap();
    }


    @PostMapping("/getSonLevel")
    @ApiOperation("获得指定一级分类下的二级分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "一级分类Id",required = true,dataType = "long",paramType = "query")
    })
    public Map getSonLevel(Long id){
        List<GoodsType> topLevel = goodsTypeService.getSonLevel(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(topLevel);
        return jsonResult.getDataMap();
    }
}
